home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: Callbacks using member functions
- Date: 17 Jan 1996 00:13:30 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4dheva$rjl@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe4.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Jan 16, 1996 16:43:58 in article <Callbacks using member functions>,
- '3mal5@qlink.queensu.ca (Lepage Marc A)' wrote:
-
-
- >I am writing a MOTIF application, and I wish to use classes for the
- >various elements of my program. MOTIF is C, and uses callbacks. I want
- >to install member functions as the callbacks, but g++ complains, I
- >suspect because of the implicit 'this' parameter. Is there a way to get
- >this to work (ie, why can't the compiler straighten everything out)?
- >
- You can't have member functions as callback directly -- except
- static functions, but they're more like ordinary functions anyway.
- One way to do is as follows:
-
- void CMyObject::SetupCallback ()
- {
- XtAddCallback(xmNactivateCallback, BleepCB, (XtPointer)this);
- ...
- }
-
- void BleepCB (Widget w, XtPointer cd, XtPointer cbs)
- {
- CMyObject * obj = (CMyObject*)cd;
- obj->MemberFunc(.....);
- }
- >I expect that I cannot use a member function as a callback, but wish to
- >confirm this before I go ahead and start using friend functions.
- >
- No, excessive use of friends is not desirable.
-
- >Does anyone have any recommendations to structuring MOTIF applications
- >with C++, and an object-oriented approach?
-
- IMHO Motif does not fit very well into the OO paradigm; however, you
- can do a reasonable implementation if you spend a little extra
- time on the design; and you know Motif reasonable well. I
- wrote a class library for Motif while learning Motif at the same time.
- Needless to say, I'm not proud of that work.
-
- --
- Pete Grant
- Kalevi, Inc.
- Object Oriented Software Development
-